//
//  SecondViewController.m
//  UIComprehensive
//
//  Created by lanou3g on 16/1/25.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "SecondViewController.h"
#import "AnimationViewController.h"
@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self ViewInit];
}
- (void)ViewInit{
    self.title = @"动画";
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"动画" style:UIBarButtonItemStylePlain target:self action:@selector(rightAction)];
    self.navigationItem.rightBarButtonItem = rightItem;
#pragma mark - 添加图片
    UIImage *image = [UIImage imageNamed:@"2.jpg"];
    UIImageView *imV = [[UIImageView alloc]initWithFrame:([UIScreen mainScreen].bounds)];
    imV.image = image;
    [self.view addSubview:imV];
#pragma mark - 动画一
    UIImageView *imV1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 180, 280)];
    imV1.layer.cornerRadius = 100;
    imV1.layer.borderWidth = 2;
    imV1.layer.masksToBounds = YES;
    NSMutableArray *arr1 = [NSMutableArray array];
    for (int i = 1; i < 18; i++) {
        [arr1 addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff",i+50]]];
    }
    [imV1 setAnimationImages:arr1];
    //每张图片播放的时间
    imV1.animationDuration = 1;
//    //循环播放几次
//    imV1.animationRepeatCount = 10;
    //开始动画
    [imV1 startAnimating];
    [self.view addSubview:imV1];
#pragma mark - 动画二
    UIImageView *imV2 = [[UIImageView alloc]initWithFrame:CGRectMake(190, 280, 180, 280)];
    imV2.layer.cornerRadius = 100;
    imV2.layer.borderWidth = 2;
    imV2.layer.masksToBounds = YES;
    NSMutableArray *arr2 = [NSMutableArray array];
    for (int i = 1; i <15; i++) {
        [arr2 addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff",i+200]]];
    }
    [imV2 setAnimationImages:arr2];
    imV2.animationDuration = 1;
    [imV2 startAnimating];
    [self.view addSubview:imV2];
#pragma mark - 动画三
    UIImageView *imV3 = [[UIImageView alloc]initWithFrame:CGRectMake(190, 0, 180, 280)];
    imV3.layer.cornerRadius = 110;
    imV3.layer.borderWidth = 2;
    imV3.layer.masksToBounds = YES;
    imV3.animationImages = @[[UIImage imageNamed:@"301.tiff"],
                             [UIImage imageNamed:@"302.tiff"],
                             [UIImage imageNamed:@"303.tiff"],
                             [UIImage imageNamed:@"304.tiff"],
                             [UIImage imageNamed:@"305.tiff"],
                             ];
    imV3.animationDuration = 1;
    [imV3 startAnimating];
    [self.view addSubview:imV3];
#pragma mark - 动画四
    UIImageView *imV4 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 280, 180, 280)];
    imV4.layer.borderWidth = 2 ;
    imV4.layer.cornerRadius = 100;
    imV4.layer.masksToBounds = YES;
    NSMutableArray *arr4 = [NSMutableArray array];
    for (int i = 1 ; i<41; i++) {
        [arr4 addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff",i]]];
    }
    [imV4 setAnimationImages:arr4];
    imV4.animationDuration = 1;
    [imV4 startAnimating];
    [self.view addSubview:imV4];

}
- (void)rightAction{
    [self.navigationController pushViewController:[AnimationViewController new] animated:YES];
}


@end
